package com.market.service.admin.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.market.bean.MarketFootprint;
import com.market.bean.MarketFootprintExample;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.CommonData;
import com.market.mapper.MarketFootprintMapper;
import com.market.service.admin.AdminFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tan
 * @date 2022年12月29日 16:55
 */
@Service
public class AdminFootprintServiceImpl implements AdminFootprintService {
    @Autowired
    MarketFootprintMapper footprintMapper;

    @Override
    public CommonData<MarketFootprint> list(BasePageInfo info, Integer goodsId, Integer userId) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        //根据name和userId条件查询
        MarketFootprintExample example = new MarketFootprintExample();
        //排序
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        MarketFootprintExample.Criteria criteria = example.createCriteria();
        //判空 增加if之后成为条件查询
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null) {
            criteria.andGoodsIdEqualTo(goodsId);
        }
        criteria.andDeletedEqualTo(false);
        List<MarketFootprint> list = footprintMapper.selectByExample(example);
        PageInfo<MarketFootprint> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }
}
